package com.example.xm.controller;

import com.example.xm.entity.Fenlei;
import com.example.xm.entity.JinduVO;
import com.example.xm.entity.Video;
import com.example.xm.service.IFenleiService;
import com.example.xm.service.IVideoService;
import com.example.xm.service.impl.VideoService;
import com.example.xm.web.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/video")
public class VideoController {
    @Autowired
    IVideoService shipinfenleiService;
    @Autowired
    private IVideoService videoService;

    @PostMapping("/add")
    public Result reg(@RequestBody Video gonggao){
        System.out.println("user"+gonggao);
        shipinfenleiService.reg(gonggao);
        return Result.success();
    }
    @PostMapping("/update")
    public Result update(@RequestBody Video gonggao){
//        System.out.println(account+"=========="+password);
        shipinfenleiService.update(gonggao);
        return Result.success();

    }
    @GetMapping("/list")
    public Result list(String name, Integer page, Integer size, Integer uid, Integer cur, Integer cid,Integer lid){
        PageInfo<Video> pageInfo= shipinfenleiService.list(name,page,size,uid,cur,cid,lid);
        return Result.success(pageInfo);
    }
    @GetMapping("/getTuijian")
    public Result getTuijian(Integer  uid){
        List<Video> pageInfo= videoService.getTuijian(uid);
        return Result.success(pageInfo);
    }
    @GetMapping("/getDetail")
    public Result getById( Integer vid,Integer uid){
        Video video= shipinfenleiService.getById(vid,uid);
        return Result.success(video);
    }
    @DeleteMapping("/delete/{ids}")
    public Result delete(@PathVariable String ids){
        String[] split = ids.split(",");
        int[] intArray = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            intArray[i] = Integer.parseInt(split[i]);
        }
        shipinfenleiService.delete(intArray);
        return Result.success();
    }
    @GetMapping("/getJindu")
    public Result getJindu(Integer  uid){
        List<Video> pageInfo= videoService.getJindu(uid);
        return Result.success(pageInfo);
    }
    @GetMapping("/getJinduByVid")
    public Result getJinduByVid(Integer  vid){

        List<JinduVO> pageInfo= videoService.getJinduByVid(vid);
        return Result.success(pageInfo);
    }
}
